package com.itheima.text1;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class Demo5Student1 {
    public static void main(String[] args) {
        TreeSet<Student1> set = new TreeSet<>(new Comparator<Student1>() {
            @Override
            public int compare(Student1 o1, Student1 o2) {
                //首要条件 按成绩排序
                int i = o1.getScore() - o2.getScore();

                int i1 = i == 0 ? o1.getAge() - o2.getAge() : i;

                return i == 0 ? o1.getName().compareTo(o2.getName()) : i1;
            }
        });

        set.add(new Student1("Tom",20,90));
        set.add(new Student1("Jerry",22,95));
        set.add(new Student1("John",20,100));
        set.add(new Student1("Lily",22,100));
        set.add(new Student1("Lucy",22,90));
        set.add(new Student1("Kevin",22,90));

        for (Student1 student1 : set) {
            System.out.println(student1);

        }
    }
}
